package com.xxxx.web.dto;

import com.xxxx.web.entity.*;
import com.xxxx.web.enums.*;
import com.xxxx.web.tools.dto.BaseDto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;

/**
 * 盘点单表类
 */
@Data
public class InventoryCheckDto extends BaseDto {


    /**
     * 是否执行库存调整
     */
    @JsonProperty("IsExcuteInventoryChange")
    private Boolean IsExcuteInventoryChange;


    /**
     * 盘点人
     */
    @JsonProperty("CheckUserId")
    private Integer CheckUserId;


    /**
     * 货主
     */
    @JsonProperty("CustomerId")
    private Integer CustomerId;


    /**
     * 单号
     */
    @JsonProperty("No")
    private String No;


    /**
     * 起始盘点时间
     */
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("BeginCheckTime")
    private LocalDateTime BeginCheckTime;


    /**
     * 仓库
     */
    @JsonProperty("WarehouseId")
    private Integer WarehouseId;


    /**
     * 盘点状态
     */
    @JsonProperty("InventoryCheckStatus")
    private Integer InventoryCheckStatus;


    /**
     * 截至盘点时间
     */
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("EndCheckTime")
    private LocalDateTime EndCheckTime;

    @JsonProperty("CheckUserDto")
    private AppUserDto CheckUserDto;

    @JsonProperty("WarehouseDto")
    private WarehouseDto WarehouseDto;

    @JsonProperty("CustomerDto")
    private CustomerDto CustomerDto;

    /**
     * 把盘点单表传输模型转换成盘点单表实体
     */
    public InventoryCheck MapToEntity() throws InvocationTargetException, IllegalAccessException {
        InventoryCheck InventoryCheck = new InventoryCheck();

        BeanUtils.copyProperties(InventoryCheck, this);

        return InventoryCheck;
    }

}
